/*
{
"状态":0,
"名称":"登录-判断token",
"作者":"马学兵",
"创建时间":"2018-07-26",
"功能":"登录-判断token",
"log": [
	{"date":"" , "dev" :"" , "content" : ""}
]
}
*/

set xact_abort on 
set nocount on

declare @company int , @user int  ,@token varchar(100) , @cmd_id varchar(1000)
declare @msg nvarchar(100)

set @token =  '{token}'
set @cmd_id = '{power}'

select @company = login_company_key , @user = login_user_key
from y_login l
inner join y_company c on l.login_company_key = c.company_key
inner join y_user u on l.login_user_key = u.user_key 
where token =@token
--and datediff(Hour, l.update_time , getdate()) < 5


if @user is null
begin
	raiserror( 'SQL:无效的token',16,1)
	return 
end

/*
if not exists(SELECT 1 FROM dbo.y_power INNER JOIN dbo.y_role_power ON y_role_power.power_key = y_power.power_key
INNER JOIN dbo.y_role_user ON y_role_user.role_key = y_role_power.role_key
INNER JOIN dbo.y_cmd ON cmd_power_id=power_id
WHERE cmd_id=@cmd_id AND user_key=@user)
begin 
	set @msg='SQL:没有操作权限'
	raiserror(@msg,16,1)
	return;
end 
*/

update y_login set update_time = getdate() where token = @token
select @company  as company_key , @user as user_key



